package org.cainiao.basic.reflect;

import java.lang.reflect.Proxy;

public class DynamicProxyExample {

    public static void main(String[] args) {
        Calculator calculator = new CalculatorImpl(); // 实际的实现类
        LoggingHandler handler = new LoggingHandler(calculator);

        Calculator proxy = (Calculator) Proxy.newProxyInstance(
            Calculator.class.getClassLoader(),
            new Class[]{Calculator.class},
            handler
        );

        Class<CalculatorImpl> calculatorClass = CalculatorImpl.class;

        int result = proxy.add(5, 3); // 调用代理的add方法
        System.out.println("Final Result: " + result);
    }

}
